package com.sunrise.generico.entidade;

import java.util.Collection;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import lombok.Getter;
import lombok.Setter;

import org.hibernate.validator.constraints.NotEmpty;

import com.sunrise.generico.entidade.iface.EntidadeManter;

@Entity
@Table(name = "pessoa")
public class Pessoa implements EntidadeManter {

	/**
	 * 
	 */
	private static final long serialVersionUID = 9043724661424862176L;

	@Id
	@SequenceGenerator(name="pk_sequence",sequenceName="pessoa_id_seq", allocationSize=1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="pk_sequence")
	@javax.persistence.Column
	@Getter @Setter
	private Long id;
	
	@NotEmpty( message="{nomeRazaoSocialObrigatorio}")
	@Column(name = "nome", length = 100, nullable = false)
	@Getter @Setter
	private String nome;

	@Column(name = "cpf", length = 14)
	@Getter @Setter
	private String cpf;
	
	@Column(name = "cnpj", length = 20)
	@Getter @Setter
	private String cnpj;
	
	@Column(name = "nomeFantasia", length = 100)
	@Getter @Setter
	private String nomeFantasia;
	
	@Column(name = "dataNascimento")
	@Getter @Setter
	private Date dataNascimento;
	
	@Column(name = "dataCriacao")
	@Getter @Setter
	private Date dataCriacao;
	
	@Column(name = "enderecoFoto", length = 100)
	@Getter @Setter
	private String enderecoFoto;

	@OneToOne
	@Getter @Setter
	private Endereco endereco;
	
	@OneToOne
	@Getter @Setter
	private Endereco enderecoEntrega;
	
	@OneToOne
	@Getter @Setter
	private Contato contato;
	
	@Column(name = "observacao", length = 200)
	@Getter @Setter
	private String observacao;
	
	@Column(name = "password", length = 200)
	@Getter @Setter
	private String password;
	
	@Column(name = "ativo")
	@Getter @Setter
	private Boolean ativo;
	
	@Column(name = "ie")
	@Getter @Setter
	private String ie;
	
	@Column(name = "crt")
	@Getter @Setter
	private String crt;
	
	
	@ManyToMany(fetch=FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE })
	@JoinTable(name="pessoa_tipopessoa", joinColumns={@JoinColumn(name="pessoa_id", referencedColumnName="id")},
		      inverseJoinColumns={@JoinColumn(name="tipopessoa_id", referencedColumnName="id")})
	@Getter @Setter
	private Collection<TipoPessoa> tiposPessoa;

}
